<template>
  <!-- 新增 -->
  <div>
    <div class="add">
      <Header :title="title" />

      <van-cell-group>
        <van-field
          v-model="username"
          required
          label="客户名称"
          placeholder="请输入名称"
        />
        <van-field
          v-model="phone"
          required
          label="联系方式"
          placeholder="请输入手机号"
        />
      </van-cell-group>
      <van-field v-model="text" label="学历" />
      <van-field v-model="tel" type="tel" label="年龄" />
      <van-field v-model="gender" type="text" label="性别" />
      <van-field v-model="city" type="text" label="所属城市" />
      <van-field v-model="company" type="text" label="公司名称" />
      <van-field v-model="job" type="text" label="职务" />
      <div></div>
      <div class="down">
        <button @click="saveClick">保存</button>
      </div>
    </div>
  </div>
</template>

<script>
import { GetDetails } from "../raxios/api";
import { GetAlterData } from "../raxios/api";
import Header from "../components/Header";
import { Toast } from 'vant';
export default {
  data() {
    return {
      basic: {},
      title: "修改客户信息",
      username: "",
      city: "",
      company: "",
      job: "",
      phone: "",
      text: "",
      gender: "",
      tel: "",
    };
  },
  methods: {
    saveClick() {
      GetAlterData({
        custName: this.username,
        cityName: this.city,
        company: this.company,
        position: this.job,
        telephone: this.phone,
        education: this.text,
        sex: this.gender,
        age: this.tel,
        id:this.$route.query.id
      }).then((res) => {
        if (res.errCode == 0) {
        //   console.log(res);
        //   alert('保存成功')
            Toast.success('提交成功');
            setTimeout(()=>{
                this.$router.go(-1)
            },500)
        }
      });
    },
  },
  components: {
    Header,
  },
  created() {
    // console.log(this.$route.query.id);
    GetDetails(this.$route.query.id).then((res) => {
      if (res.errCode == 0) {
        // console.log(res.data);
        let basic = res.data;
        this.username = basic.custName,
          this.city = basic.cityName,
          this.company = basic.company,
          this.job = basic.position,
          this.phone = basic.telephone,
          this.text = basic.education,
          this.gender = basic.sex,
          this.tel = basic.age;
      }
    });
  },
};
</script>
 
<style lang="less" scoped>
.van-cell-group {
  margin: 0.1rem 0;
}
/deep/.add {
  position: relative;
  height: 100vh;
  .down {
    width: 100%;
    height: 0.6rem;
    background-color: #fff;
    position: absolute;
    bottom: 0;
    left: 0;
    button {
      width: 96%;
      height: 0.4rem;
      position: absolute;
      left: 50%;
      margin-left: -48%;
      top: 0.1rem;

      background-color: #cde7ff;
      color: #fff;
      border-radius: 0.4rem;
      font-size: 0.16rem;
      border: 0;
    }
  }
}
</style>